﻿using DevExpress.XtraEditors.Controls;
using RecruitStudents.Client.BLL;
using RecruitStudents.Utility;
using RecruitStudents.Utility.Helper;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RecruitStudents.Client.Examinee
{
    public partial class Examinee_StudentRegistration_Pack : BaseForm
    {
        string Sex = string.Empty;
        string SignUpStudentsSpecialityID = string.Empty;
        string ExamPlaceNo = string.Empty;
        string Spec = string.Empty;
        ServiceExaminee serviceExam = new ServiceExaminee();
        ServiceComm serviceComm = new ServiceComm();
        public Examinee_StudentRegistration_Pack(string strSignUpStudentsSpecialityID, string strSex,
            string strExamPlaceNo, string strSpec)
        {
            InitializeComponent();
            ExamPlaceNo = strExamPlaceNo;
            Spec = strSpec;
            SignUpStudentsSpecialityID = strSignUpStudentsSpecialityID;
            Sex = strSex;
            this.ddlExamCity.Properties.Columns.Clear();
            this.ddlExamCity.Properties.Columns.Add(new LookUpColumnInfo("ExamPlaceNO", 30, "考点代码"));
            this.ddlExamCity.Properties.Columns.Add(new LookUpColumnInfo("ExamPlaceName", 55, "考点名称"));
            this.ddlSpec.Properties.Columns.Clear();
            this.ddlSpec.Properties.Columns.Add(new LookUpColumnInfo("SpecialityKindsNO", 30, "专业代码"));
            this.ddlSpec.Properties.Columns.Add(new LookUpColumnInfo("SpecialityKindsName", 55, "专业名称"));
            BindExamPlace();
        }

        private void BindExamPlace()
        {
            #region 绑定考点下拉列表框
            using (DataTable dtProvice = serviceComm.GetExamPlaceTable())
            {
                this.ddlExamCity.Properties.ValueMember = "ExamPlaceNO";
                this.ddlExamCity.Properties.DisplayMember = "ExamPlaceName";
                this.ddlExamCity.Properties.DataSource = dtProvice;
                this.ddlExamCity.Properties.NullText = "";
                this.ddlExamCity.EditValue = ExamPlaceNo;
            }
            #endregion
        }

        #region 绑定专业类别
        /// <summary>
        /// 绑定专业类别
        /// </summary>
        /// <param name="dtBoundCheckBoxListData"></param>
        private void BoundSpecialityKinds(string strExamPlaceID)
        {
            this.ddlSpec.Properties.DataSource = null;
            //绑定专业类别
            string strSex = Sex;
            using (DataTable dtSpecialityKinds = serviceComm.GetSpecialityKindsTableByExamPlaceID(strExamPlaceID, strSex))
            {
                this.ddlSpec.Properties.DataSource = dtSpecialityKinds;
                this.ddlSpec.Properties.ValueMember = "SpecialityKindsNO";
                this.ddlSpec.Properties.DisplayMember = "SpecialityKindsName";
                this.ddlSpec.Properties.NullText = "";
                this.ddlSpec.EditValue = Spec;
            }
        }
        #endregion

        private void btnTZ_Click(object sender, EventArgs e)
        {
            if (txtRemarks.Text.Trim() == "")
            {
                txtRemarks.Focus();
                DevHelper.ShowErrorMessageBox("请先输入原因再进行操作！");
                return;
            }
            if (serviceExam.UpdateSignUpStudentsSpeciality_TZ(SignUpStudentsSpecialityID, txtRemarks.Text))
            {
                ddlExamCity.Enabled = true;
                ddlSpec.Enabled = true;
                btnSave.Enabled = true;
                btnTZ.Enabled = false;
            }
        }

        private void btnTK_Click(object sender, EventArgs e)
        {
            if (txtRemarks.Text.Trim() == "")
            {
                txtRemarks.Focus();
                DevHelper.ShowErrorMessageBox("请先输入原因再进行操作！");
                return;
            }
            if (serviceExam.UpdateSignUpStudentsSpeciality_TZ(SignUpStudentsSpecialityID, txtRemarks.Text))
            {
                this.DialogResult = DialogResult.OK;
                DevHelper.ShowInfoMessageBox("退款成功！");
            }
        }

        private void ddlExamCity_EditValueChanged(object sender, EventArgs e)
        {
            BoundSpecialityKinds(ddlExamCity.EditValue.ToSafeString());
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (ddlExamCity.EditValue == null || ddlExamCity.EditValue.ToSafeString().Length == 0)
            {
                DevHelper.ShowErrorMessageBox("请先选择考点！");
                ddlExamCity.Focus();
                return;
            }
            if (ddlSpec.EditValue == null || ddlSpec.EditValue.ToSafeString().Length == 0)
            {
                DevHelper.ShowErrorMessageBox("请先选择专业！");
                ddlSpec.Focus();
                return;
            }
            if (serviceExam.UpdateSignUpStudentsSpeciality(SignUpStudentsSpecialityID, ddlExamCity.EditValue.ToSafeString(), ddlSpec.EditValue.ToSafeString(), txtRemarks.Text))
            {
                this.DialogResult = DialogResult.OK;
                DevHelper.ShowInfoMessageBox("调整专业成功！");
            }
        }
    }
}
